package cn.skillith.showcompanybackend.mapper;

import cn.skillith.showcompanybackend.entity.ContactMessage;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface ContactMessageMapper extends JpaRepository<ContactMessage, Long> {
    
    @Query("SELECT c FROM ContactMessage c WHERE c.status = :status ORDER BY c.createdAt DESC")
    Page<ContactMessage> findByStatus(@Param("status") String status, Pageable pageable);
    
    @Query("SELECT c FROM ContactMessage c ORDER BY c.createdAt DESC")
    Page<ContactMessage> findAllOrderByCreatedAtDesc(Pageable pageable);
    
    @Query("SELECT COUNT(c) FROM ContactMessage c WHERE c.status = :status")
    long countByStatus(@Param("status") String status);
    
    @Query("SELECT c FROM ContactMessage c WHERE c.deviceFingerprint = :deviceFingerprint ORDER BY c.createdAt DESC")
    List<ContactMessage> findByDeviceFingerprint(@Param("deviceFingerprint") String deviceFingerprint);
}